package com.dreamer.service.mobile.impl;

import com.dreamer.domain.mall.delivery.DeliveryItem;
import com.dreamer.domain.mall.delivery.DeliveryNote;
import com.dreamer.domain.mall.goods.Goods;
import com.dreamer.domain.mall.transfer.Transfer;
import com.dreamer.domain.pmall.order.Order;
import com.dreamer.domain.pmall.order.OrderItem;
import com.dreamer.domain.socket.Message;
import com.dreamer.domain.user.AccountsRecord;
import com.dreamer.domain.user.AddressClone;
import com.dreamer.domain.user.Agent;
import com.dreamer.domain.user.AgentLevelName;
import com.dreamer.service.mobile.AgentHandler;
import com.dreamer.service.mobile.NoticeHandler;
import com.dreamer.service.mobile.factory.WxConfigFactory;
import com.dreamer.util.TokenInfo;
import com.wxjssdk.JSAPI;
import com.wxjssdk.dto.SdkResult;
import com.wxjssdk.util.DateUtil;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.management.resources.agent;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by huangfei on 05/07/2017.
 */
@Service
public class NoticeHandlerImpl implements NoticeHandler {

    @Autowired
    private WxConfigFactory wxConfigFactory;

    @Autowired
    private AgentHandler agentHandler;


    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 调用微信通知 通知客户 资金通知
     *
     * @param records
     */
    public void noticeAccountRecords(List<AccountsRecord> records) {
        //如果是联盟单位不通知获得奖励
        String template_id = "f056H6cQKJWO7YyVgeZC0WFGZ7HDcsLbc9yoSF4Wnxc";
        Map<String, Object> data;
        for (AccountsRecord record : records) {
            if (record.getAgent().getAgentCode() != null) {
                String ln = agentHandler.getLevelName(record.getAgent());
                if (ln.contains(AgentLevelName.联盟单位.toString())) {
                    continue;//跳过
                }
            }
            String url = "http://ht.zmz365.com/zz/mobile/accounts/records.html?stateType=" + record.getAccountsType().getState();
            data = new HashMap<>();
            data.put("first", createItemMap(record.getInfo()));//变动原因
            data.put("keyword2", createItemMap(record.getAmount()));
            data.put("keyword1", createItemMap(DateUtil.formatDate(record.getUpdateTime())));
            data.put("keyword3", createItemMap(record.getNowAmount()));
            data.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
            sendTemplateMessage(record.getAgent().getWxOpenid(), template_id, url, data);

        }
    }

    /**
     * 调用微信通知 通知客户 转货通知
     *
     * @param records
     */
    public void noticeTransfer(Transfer transfer) {

        String url = "http://ht.zmz365.com/zz/mobile/transfer/records.html";
        Agent fromAgent = transfer.getFromAgent();
        Agent toAgent = transfer.getToAgent();
        String template_id;
        StringBuffer stringBuffer = new StringBuffer();
        Map<String, Object> fromData = new HashMap<>();
        stringBuffer = new StringBuffer();
        StringBuffer finalStringBuffer = stringBuffer;
        transfer.getItems().stream().forEach(p -> {
            finalStringBuffer.append(p.getGoods().getName());
            finalStringBuffer.append("X");
            finalStringBuffer.append(p.getQuantity());
            finalStringBuffer.append("\r\n");
        });
        //如果收货人不是公司
        if(!toAgent.isMutedUser()){
            Agent parent = toAgent;
            Integer index = 0;
            while (parent!=null&&!parent.isMutedUser()){
                index ++ ;
                //通知
                if(index>3&&!agentHandler.isSuperVip(parent)){
                    parent = parent.getParent();
                    continue;
                }
                //入库通知
                template_id = "tThNkvzUdGkBzxTX6bFhU-2lzuefq2wRZjHvdNy4bVs";
                Map<String, Object> toData = new HashedMap();
                fromData = new HashedMap();
                toData.put("first", createItemMap("您好"+toAgent.getRealName()+"有一批产品入库!"));
                toData.put("keyword1", createItemMap(stringBuffer.toString()));
                SimpleDateFormat df1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
                toData.put("keyword2", createItemMap(df1.format(new Date())));
                toData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
                sendTemplateMessage(parent.getWxOpenid(), template_id, url, toData);
                parent = parent.getParent();
            }
        }

        //出库通知

        template_id = "at6hvBkHFeTpyZq1kseYE5aoS3Za2KoQ5DfU5jKaneM";
        fromData.put("first", createItemMap("您好，您有一批产品出库，请查看!"));
        fromData.put("keyword1", createItemMap(transfer.getId()));
        fromData.put("keyword2", createItemMap(stringBuffer.toString()));
        fromData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(fromAgent.getWxOpenid(), template_id, url, fromData);
    }


    //通知上面的所有团队
    @Override
    public void noticeTransferToBoss(Transfer transfer) {
//        List<Agent> agents = agentHandler.findBosses(transfer.getToAgent());
//        for(Agent agent : agents){//通知团队领导人
//            String url = "http://ht.hzc365.com/hzc/mobile/transfer/records.html";
//            Agent fromAgent = transfer.getFromAgent();
//            Agent toAgent = transfer.getToAgent();
//            //入库通知
//            String template_id = "8bOuv5fBGTMsbjws4s1zemIRaSRHqF-RtxiI_AjroCc";
//            Map<String, Object> toData = new HashedMap();
//            toData.put("first", createItemMap("您好，您团队的"+transfer.getToAgent().getRealName()+transfer.getToAgent().getAgentCode()+"的购买了一批产品，请查看!"));
//            StringBuffer stringBuffer = new StringBuffer();
//            transfer.getItems().stream().forEach(p -> {
//                stringBuffer.append(p.getGoods().getName());
//                stringBuffer.append("X");
//                stringBuffer.append(p.getQuantity());
//                stringBuffer.append("\r\n");
//            });
//            toData.put("keyword1", createItemMap(stringBuffer.toString()));
//            toData.put("keyword2", createItemMap("请前往系统查看!"));
//            toData.put("remark", createItemMap("和之初一站式购物，让更多的人用上优惠的好产品!感谢您的使用！"));
//            sendTemplateMessage(agent.getWxOpenid(), template_id, url, toData);
//        }
    }

    /**
     * 调用微信通知 通知客户 待发货通知
     *
     * @param note
     */
    public void noticeDeliveryNote(DeliveryNote note) {
        Agent fromAgent = note.getFromAgent();
        Agent toAgent = note.getToAgent();
        String template_id = "foz85Roew7Mm88Hxk6yOz9yr0oZOOfYtDSO20wtbozs";
        String url = "http://ht.zmz365.com/zz/mobile/delivery/records.html";
        Map<String, Object> fromAgentData = new HashedMap();
        Map<String, Object> toAgentData = new HashedMap();
        //出货人
        fromAgentData.put("first", createItemMap("您好，您的发货订单提交成功，即将发给" + toAgent.getRealName()));
        //产品数量
        String stringBuffer = items2String(note.getDeliveryItems());

        fromAgentData.put("keyword1", createItemMap(stringBuffer));
        fromAgentData.put("keyword2", createItemMap(DateUtil.formatDate(note.getUpdateTime())));
        fromAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(fromAgent.getWxOpenid(), template_id, url, fromAgentData);
        if (fromAgent.getId().equals(toAgent.getId())) return;//如果是自己给自己发货就不用提醒了
        //收货人
        toAgentData.put("first", createItemMap("您好," + note.getApplyAgent().getRealName() + "给您的发货订单已经提交，即将发货！"));
        toAgentData.put("keyword1", createItemMap(stringBuffer));
        toAgentData.put("keyword2", createItemMap(DateUtil.formatDate(note.getUpdateTime())));
        toAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(toAgent.getWxOpenid(), template_id, url, toAgentData);
    }


//    /**
//     * 优惠商城购买通知
//     *
//     * @param order
//     */
//    public void noticeOrderToParent(Order order) {
//
//    }
//
//    private void noticeOrder(){
//
//    }


    /**
     * 调用微信通知 通知客户 取消发货通知
     *
     * @param note
     */
    public void noticeDeliveryNoteDeleted(DeliveryNote note) {
        Agent fromAgent = note.getFromAgent();
        Agent toAgent = note.getToAgent();
        String template_id = "foz85Roew7Mm88Hxk6yOz9yr0oZOOfYtDSO20wtbozs";
        String url = "http://ht.zmz365.com/zz/mobile/delivery/records.html";
        Map<String, Object> fromAgentData = new HashedMap();
        Map<String, Object> toAgentData = new HashedMap();
        //出货人
        fromAgentData.put("first", createItemMap("您好，您发给" + toAgent.getRealName() + "的订单取消成功，产品已退回到您的库存!"));
        //产品数量
        String stringBuffer = items2String(note.getDeliveryItems());

        fromAgentData.put("keyword1", createItemMap(stringBuffer));
        fromAgentData.put("keyword2", createItemMap(DateUtil.formatDate(note.getUpdateTime())));
        fromAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(fromAgent.getWxOpenid(), template_id, url, fromAgentData);
        //收货人
        toAgentData.put("first", createItemMap("您好," + fromAgent.getRealName() + "给您的发货订单已经取消，不会发货！"));
        toAgentData.put("keyword1", createItemMap(stringBuffer));
        toAgentData.put("keyword2", createItemMap(DateUtil.formatDate(note.getUpdateTime())));
        toAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(toAgent.getWxOpenid(), template_id, url, toAgentData);
    }


    /**
     * 调用微信通知 通知客户 已经发货通知
     *
     * @param note
     */
    public void noticeDelived(DeliveryNote note) {
        Agent fromAgent = note.getFromAgent();
        Agent toAgent = note.getToAgent();
        String template_id = "qO_N6O4DGdGOccpdyh_O_XcN4OmG3lFaVTSa22srb3w";
        String url = "http://ht.zmz365.com/zz/mobile/delivery/records.html";
        Map<String, Object> fromAgentData = new HashedMap();
        Map<String, Object> toAgentData = new HashedMap();
        //出货人
        fromAgentData.put("first", createItemMap("您好，发给" + toAgent.getRealName() + "订单已经发货！"));
        //产品数量
        String stringBuffer = items2String(note.getDeliveryItems());
        fromAgentData.put("keyword1", createItemMap(stringBuffer));
        fromAgentData.put("keyword3", createItemMap(note.getLogistics()));
        fromAgentData.put("keyword4", createItemMap(note.getLogisticsCode()));
        fromAgentData.put("keyword5", createItemMap(note.getAddress().getAddress()));
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        fromAgentData.put("keyword2",createItemMap(df1.format(new Date())));
        fromAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(fromAgent.getWxOpenid(), template_id, url, fromAgentData);
        if (fromAgent.getId().equals(toAgent.getId())) return;
        //收货人
        toAgentData.put("first", createItemMap("您好," + fromAgent.getRealName() + "发给您的发货订单已经发货，请耐心等待产品到来！"));
        toAgentData.put("keyword1", createItemMap(note.getId()));
        toAgentData.put("keyword3", createItemMap(note.getLogistics()));
        fromAgentData.put("keyword4", createItemMap(note.getLogisticsCode()));
        fromAgentData.put("keyword5", createItemMap(note.getAddress().getProvince() + note.getAddress().getCity() + note.getAddress().getCounty() + note.getAddress().getAddress()));
        fromAgentData.put("keyword2",createItemMap(df1.format(new Date())));
        toAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(toAgent.getWxOpenid(), template_id, url, toAgentData);
    }


    @Override
    public void noticeOrder(Order order) {
        Agent toAgent = order.getUser();
        AddressClone addressClone = order.getAddressClone();
        String name = addressClone.getConsignee();
        String template_id = "qO_N6O4DGdGOccpdyh_O_XcN4OmG3lFaVTSa22srb3w";
        String url = "http://ht.zmz365.com/zz/pm/order/myOrder.html";
        Map<String, Object> fromAgentData = new HashedMap();
        //出货人
        fromAgentData.put("first", createItemMap("您好，您发给" + name + "订单已经发货！"));
        //产品数量
        String stringBuffer = items2StringOrder(order.getItems());
        fromAgentData.put("keyword1", createItemMap(stringBuffer));
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        fromAgentData.put("keyword2",createItemMap(df1.format(new Date())));
        fromAgentData.put("keyword3", createItemMap(order.getLogistics()));
        fromAgentData.put("keyword4", createItemMap(order.getLogisticsCode()));
        fromAgentData.put("keyword5", createItemMap(addressClone.getProvince() + addressClone.getCity() + addressClone.getCounty() + addressClone.getAddress()));
        fromAgentData.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(toAgent.getWxOpenid(), template_id, url, fromAgentData);
    }

    @Override
    public void noticeNewUser(Agent agent) {
        String template_id = "dAtw17iu3iqLcBPzMDaK3nLRUpdU6oZkjA8d13G0OJo";
        String url = "http://ht.zmz365.com/zz/mobile/contacts.html";
        Map<String, Object> data = new HashedMap();
        data.put("first", createItemMap("您好，您新增了一位新的客户，请跟进服务！"));
        data.put("keyword1", createItemMap(agent.getRealName()));
        data.put("keyword2", createItemMap(DateUtil.formatDate(new Date())));
        data.put("remark", createItemMap("不完善信息也可以直接购买,也可以转发分享优惠商城！"));
        sendTemplateMessage(agent.getParent().getWxOpenid(), template_id, url, data);
    }

    @Override
    public void noticeMessage(Message message) {
        Agent agent = agentHandler.get(Integer.valueOf(message.getToId()));
        String template_id = "36Vk8fqZT7C-BPfLz5iWWVIi-X0mQU5a6D5MjaGQgws";
        String url;
        Map<String, Object> data = new HashedMap();
        if(message.getFromId().indexOf("G")>-1){//群聊
            String tem = message.getFromId().replace("G","");
            url = "http://ht.zmz365.com/zz/mobile/group/chat.html?gid=" + tem;
            data.put("first", createItemMap("您有一条来自" + message.getName() + "的群消息!"));
        }else {
            url = "http://ht.zmz365.com/zz/mobile/chat.html?toId=" + message.getFromId();
            data.put("first", createItemMap("您的好友" + message.getName() + "给您发送了一条留言！"));
        }


        data.put("keyword1", createItemMap(message.getName()));
        switch (message.getType()) {
            case "voice":
                data.put("keyword2", createItemMap("[语音消息，点我查看]"));
                break;
            case "img":
                data.put("keyword2", createItemMap("[图片消息，点我查看]"));
                break;
            default:
                data.put("keyword2", createItemMap(message.getMsg()));
        }
        data.put("keyword3", createItemMap(DateUtil.formatDate(new Date())));
        data.put("remark", createItemMap("和信时代,微商未来,让更多的人用上优惠的好产品!"));
        sendTemplateMessage(agent.getWxOpenid(), template_id, url, data);
    }

    private String items2String(Set<DeliveryItem> items) {
        StringBuffer stringBuffer = new StringBuffer();
        items.stream().forEach(p -> {
                    stringBuffer.append(p.getGoods().getName());
                    stringBuffer.append("X");
                    stringBuffer.append(p.getQuantity());
                    stringBuffer.append("\r\n");
                }
        );
        return stringBuffer.toString();
    }

    private String items2StringOrder(Set<OrderItem> items) {
        StringBuffer stringBuffer = new StringBuffer();
        items.stream().forEach(p -> {
                    if(p.getPmallGoods()==null && p.getGoods()!=null){
                        stringBuffer.append(p.getGoods().getName());
                        stringBuffer.append("X");
                        stringBuffer.append(p.getQuantity());
                        stringBuffer.append("\r\n");
                    }else if(p.getPmallGoods()!=null && p.getGoods()==null){
                        stringBuffer.append(p.getPmallGoods().getName());
                        stringBuffer.append("X");
                        stringBuffer.append(p.getQuantity());
                        stringBuffer.append("\r\n");
                    }

                }
        );
        return stringBuffer.toString();
    }


    private void sendTemplateMessage(String openid, String template_id, String url, Map<String, Object> data) {
        Runnable runnable = () -> {
            try {
                SdkResult sdkResult = JSAPI.sendTemplateMessage(TokenInfo.getAccessToken(wxConfigFactory.getBaseConfig().getAppid()), openid, template_id, url, data);
                if (!sdkResult.isSuccess()) {
                    logger.error("通知失败内容,{},{},{}", data.toString(), sdkResult.getError(), openid);
                }else {
//                    logger.error("通知成功内容,{},{}", openid,data.toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        };
        Thread thread = new Thread(runnable);
        thread.start();
    }

    private Map createItemMap(Object value) {
        Map map = new HashedMap();
        map.put("value", value + "\r\n");
        map.put("color", "#000000");
        return map;
    }

    private Integer[] fordel(Integer[] nums,int k){
        for (int i = k; i < nums.length; i++) {
            nums[i]=nums[i+1];
        }
        return nums;
    }

    @Override
    public void niticeJH(Agent agent,Integer goodsIds[], Integer[] amounts, Double zong) {
        String template_id="Apaka4hm4uk0sevkWAA3KGnf7ctsKOMh7xcPT4Mpf8c";
        String goodId="";
        for (int i = 0; i < goodsIds.length; i++) {
            if(i==goodsIds.length-1){
                goodId=goodId+goodsIds[i];
            }else{
                goodId=goodId+goodsIds[i]+"-";
            }
        }
        String amount="";
        for (int i = 0; i < amounts.length; i++) {
            if(i==amounts.length-1){
                amount=amount+amounts[i];
            }else{
                amount=amount+amounts[i]+"-";
            }
        }
        Agent agent1=agent.getParent();
        String url = "http://ht.zmz365.com/zz/mobile/goods/qr.html?uid="+agent.getId()+"&goodId="+goodId+"&amount="+amount+"&zong="+zong;
       System.out.println(url);
        Map<String, Object> data = new HashedMap();
        data.put("first", createItemMap("您好，您有进货订单，请确认！"));
        data.put("keyword1", createItemMap(agent.getRealName()));
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        data.put("keyword2", createItemMap(df.format(new Date())));
        data.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(agent1.getWxOpenid(), template_id, url, data);
    }

    @Override
    public void niticeJH(Agent agent,Agent parent,Integer goodsIds[], Integer[] amounts, Double zong) {
        String template_id="Apaka4hm4uk0sevkWAA3KGnf7ctsKOMh7xcPT4Mpf8c";
        String goodId="";
        for (int i = 0; i < goodsIds.length; i++) {
            if(i==goodsIds.length-1){
                goodId=goodId+goodsIds[i];
            }else{
                goodId=goodId+goodsIds[i]+"-";
            }
        }
        String amount="";
        for (int i = 0; i < amounts.length; i++) {

            if(i==amounts.length-1){
                amount=amount+amounts[i];
            }else{
                amount=amount+amounts[i]+"-";
            }
        }
        String url = "http://ht.zmz365.com/zz/mobile/goods/qr.html?uid="+agent.getId()+"&goodId="+goodId+"&amount="+amount+"&zong="+zong;
        Map<String, Object> data = new HashedMap();
        data.put("first", createItemMap("您好，您有进货订单，请确认！"));
        data.put("keyword1", createItemMap(agent.getRealName()));
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        data.put("keyword2", createItemMap(df.format(new Date())));
        data.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(parent.getWxOpenid(), template_id, url, data);
        if(agent.getParent().getParent().getId()==parent.getId()){
            String url1 = "http://ht.zmz365.com/zz/mobile/goods/qr1.html?uid="+agent.getId()+"&goodId="+goodId+"&amount="+amount+"&zong="+zong;
            Map<String, Object> data1 = new HashedMap();
            data1.put("first", createItemMap("您好，您的下级"+agent.getRealName()+"在"+parent.getRealName()+"有进货订单！"));
            data1.put("keyword1", createItemMap(agent.getRealName()));
            SimpleDateFormat df1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
            data1.put("keyword2", createItemMap(df1.format(new Date())));
            data1.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
            sendTemplateMessage(agent.getParent().getWxOpenid(), template_id, url1, data1);
        }
    }

    @Override
    public void niticeJHTZ(Integer uid, Integer toUid) {
        String template_id="Lg_TArqKyhZ3DYneAEd3bs78t7xtswr0qzF2CW3gAX8";
        String url = "http://ht.zmz365.com/zz/mobile/goods/transfer1.html?uid="+uid+"&toUid="+toUid;
        Agent parent=agentHandler.get(toUid);
        Map<String, Object> data = new HashedMap();
        data.put("first", createItemMap("您好，您有一个你的上级推送给您的进货链接，请点击查看！"));
        data.put("keyword1", createItemMap("进货需求"));
        data.put("keyword2", createItemMap(parent.getRealName()));
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        data.put("keyword3", createItemMap(df.format(new Date())));
        data.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(parent.getWxOpenid(), template_id, url, data);
    }
    @Override
    public void niticeSonTranfer(Transfer transfer){
        String template_id="lOsM2ziEI4ZHDalEaGc2DA_Is4hRqxqwxOifCZPCrdw";
        String url="http://ht.zmz365.com/zz/mobile/transfer/sonrecords.html";
        Agent agent=transfer.getToAgent();
        Agent parent=agent.getParent();
        Map<String, Object> data = new HashedMap();
        data.put("first", createItemMap("您好，您的下级"+agent.getRealName()+"在公司进货，请点击查看！"));
        data.put("keyword1", createItemMap(agent.getRealName()));
        data.put("keyword2", createItemMap(transfer.getVoucher()));
        data.put("keyword3", createItemMap(transfer.getVoucher()));
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");//设置日期格式
        data.put("keyword4", createItemMap(df.format(new Date())));
        data.put("remark", createItemMap("纵姿私人基因定制，让更多的人认知自己的肌肤真实状况，用上最适合自己肌肤的产品！"));
        sendTemplateMessage(parent.getWxOpenid(), template_id, url, data);
    }
}
